<template>
  <div class="uploadtemp">
    <uploader :options="options" class="uploader-example"  @file-success="onFileSuccess" :file-status-text="statusText">
      <uploader-unsupport></uploader-unsupport>
      <uploader-drop class="uploaderDrop">
        <uploader-btn v-if="(isShowBtn|| isShowBtn==undefined || isShowBtn==null)" :attrs="attrs" class="uploaderBtn">点击选择文件{{isShowBtn}}</uploader-btn>
      </uploader-drop>
      <uploader-list  v-show="panelShow"></uploader-list>
    </uploader>
  </div>
</template>
<script>
import baseApi from 'plugins/axios/baseApi.js';
import planApi from 'plugins/axios/planApi.js';
export default {
  name: 'uploadtemp',
  props:{
    attrs:{
      type:Object,
      default:function(){ 
        return {
          accept:'document/*' 
        }
      }
    },
    upLoadType:{
      type:[Number,String]
    },
    isProcessType:{
      type:[Number,String]
    },
    drawNo:{
       type:String
    },
    processId:{
      type:[Number,String]
    },
    taskTotalId:{
      type:[Number,String]
    },
    isShowBtn:{
    },
    
  },
  data (){
    return {
        options: {
          target: baseApi.bigFileUpload(),
          singleFile:true,/**单文件上传 */
          chunkSize:20*1024*1024,/**每块儿大小 */
          testChunks: false,/** */
        },
        statusText:{
          success: '成功了',
          error: '出错了',
          uploading: '上传中',
          paused: '暂停中',
          waiting: '等待中'
        },
        panelShow:true,
        workTime:{
          itemType:null,
          startTime:null,
          endTime:null,
          taskTotalId:null,
        }
    }
  },
  watch:{
    
  },
  mounted(){},
  created(){

  },
  methods:{
    /**上传成功后*/ 
    onFileSuccess(){
      let self = this;
      const file = arguments[0].file;
      baseApi.mergeUpload({identifier:arguments[0].uniqueIdentifier}).then(res=>{
        let postData={
        drawNo:self.drawNo,
        type:self.upLoadType,
        path:res.content,
        processId:self.processId
        }
        let param = {
          itemType:self.isProcessType==1?13:self.upLoadType,
          startTime:new Date(),
          endTime:null,
          taskTotalId:self.taskTotalId,
        }
        self.insertDzjz(param);
        baseApi.insertDrawInfoUpload(postData).then(result=>{
          self.panelShow = false
          self.$emit('insert-success',result)
        })
      }).catch(error=>{
        console.log(error);
      })
    },
    /**员工工作内容适配器 */
    workAdapter(type){
      /**
       * 1 计划导入
        2 图纸上传
        3 工艺上传
        4 图形文件上传
        5 完成资料上传
       * 
       */
      let self = this;
      switch (type) {
        case '1':self.insertDzjz();break;
        case '2':self.insertDzjz();break;
        case '3':self.insertDzjz();break;
        default:
          break;
      }
    },
    /**员工工时统筹 */
    insertDzjz(param){
      let self = this;
      // let param={
      //   itemType:self.workTime.itemType,
      //   startTime:self.workTime.startTime,
      //   endTime:self.workTime.endTime,
      //   taskTotalId:self.workTime.taskTotalId,
      // };
      planApi.insertDzjz(param).then(res=>{
        console.log(res.content);
      });
    },
  }
}
</script>
<style lang="stylus" scoped>
.uploader-example
  margin-bottom 10px
 .uploaderBtn 
  background $theme-color
  color #fff
  border none
  padding 9px 15px
  font-size 12px
  border-radius 3px
  &:hover
    background $theme-color
.uploaderDrop
  border none 
  background none
  padding 0
</style>